package cn.sofwin.demo.web.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

import cn.sofwin.core.utils.HttpUtils;
import cn.sofwin.demo.web.entity.User;
import cn.sofwin.demo.web.service.UserService;
import cn.sofwin.demo.web.service.impl.UserServiceImpl;
import lombok.extern.slf4j.Slf4j;

/**
 * 用户相关的servlet
 * @author LetCode
 * @since 1.0
 */
@Slf4j
@WebServlet("/demo/user")
public class UserServlet extends HttpServlet {

    /** 用户服务的实例 */
    private UserService userService = UserServiceImpl.getInstance();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        log.warn("收到用户列表查询请求...");

        List<User> userList = userService.all();
        HttpUtils.writeJson(resp, userList);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
